<?php

/**
 * @author Immanuel Bauer | 0626117
 */
class WorkintervalJSON {
	
	/**
	 * Generates the JSON view for the given Workinterval model object.
	 * @param Workinterval $workinterval
	 * @return string
	 */
	public static function getView($workinterval){
		if(is_array($workinterval)){
			$a = array();
			$wc = count($workinterval);
			for($c = 0; $c < $wc; $c++){
				$wi = $workinterval[$c];
				$wa = array(
					'id' => $wi->getID(),
					'user' => $wi->getUserID(),
					'sD' => $wi->getStartDate(),
					'eD' => $wi->getEndDate()
				);
				array_push($a, $wa);
			}
		} else {
			$a = array(
					'id' => $workinterval->getID(),
					'user' => $workinterval->getUserID(),
					'sD' =>  $workinterval->getStartDate(),
					'eD' =>  $workinterval->getEndDate()
				);
		}		
		
		$res = new ResultJSON(false, session_id());
		$res->addItem('wI', $a);
		
		return $res->renderView();
	}
	
}

?>